//
// Created by Jisam on 2024/5/28.
//
#include "iostream"
#include "queue"
using namespace std;
#define endl "\n"
#define x first
#define y second
#define INF 0x3f3f3f3f
#define PII pair<int,int>
const int N = 31;
const int mod = 1e9 + 7;
int a[N][N][N];
struct node {
    int x, y, z;
    int step;
    friend bool operator <(node a,node b){
        return a.step > b.step;
    }
} ss, ee;
int dx[] = {-1, 1, 0, 0, 0, 0,};
int dy[] = {0, 0, -1, 1, 0, 0,};
int dz[] = {0, 0, 0, 0, -1, 1,};
int L, R, C;

bool check(int x, int y) {
    return x > 0 && x <= y;
}

void bfs(node ss) {
    priority_queue<node> q;
    q.push(ss);
    while (!q.empty()) {
        node t = q.top();
        q.pop();
        a[t.x][t.y][t.z] = 2;
        if (t.x == ee.x && t.y == ee.y && t.z == ee.z) {
            ee.step = t.step;
            return;
        }
        for (int i = 0; i < 6; i++) {
            int tx = t.x + dx[i];
            int ty = t.y + dy[i];
            int tz = t.z + dz[i];
            if (check(tx, L) && check(ty, R) && check(tz, C) &&  a[tx][ty][tz] == 1) {
                q.push((node) {tx, ty, tz, t.step + 1});

                //                printf("{%d %d %d %d}", tx, ty, tz, t.step + 1);

            }
        }

    }

}

int  main() {
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    while (cin >> L >> R >> C && L && R && C) {
//        vector<vector<vector<int>>> a(L + 1,vector<vector<int>>(R + 1,vector<int>(C + 1,0)));

        for (int i = 1; i <= L; ++i) {
            for (int j = 1; j <= R; ++j) {
                for (int k = 1; k <= C; ++k) {
                    char x;
                    cin >> x;

                    if (x == '.') {
                        a[i][j][k] = 1;
                    } else if (x == '#') {
                        a[i][j][k] = 0;
                    } else if (x == 'S') {
                        a[i][j][k] = 1;
                        ss.step = 0;
                        ss.x = i;
                        ss.y = j;
                        ss.z = k;
                    } else if (x == 'E') {
                        a[i][j][k] = 1;
                        ee.x = i;
                        ee.y = j;
                        ee.z = k;
                        ee.step = -1;
                    }

                }
            }
        }
//        for (int i = 1; i <= L; ++i) {
//            for (int j = 1; j <= R; ++j) {
//                for (int k = 1; k <= C; ++k) {
//                    cout << a[i][j][k];
//                }cout <<endl;}cout <<endl;}

        bfs(ss,a);

        if (ee.step == -1) cout << "Trapped!\n";
        else cout << "Escaped in " << ee.step << " minute(s).\n";
    }

    return 0;
}